package com.edgclub.edg.uc;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.edgclub.edg.R;

/**
 * 拆红包对话框
 * 
 */
public class OpenRedDialog extends Dialog {

	private ImageView close,logo;
	private TextView nick,hongbao_text,tv_other;
	private FrameLayout ll_bg;

	private Context context;

	private Dialog dialog;

	private OpenRedDialog instance;

	private FrameLayout ll_open;


	public static OpenRedDialog create(Context context, boolean hasCancle) {
		OpenRedDialog instance = new OpenRedDialog(context, hasCancle);
		return instance;

	}

	private OpenRedDialog(Context context, boolean hasCancle) {
		super(context, R.style.MyAlertDialog);
		init(context, hasCancle);
	}

	private void init(Context context, boolean hasCancle) {
		this.context = context;
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.width = context.getResources().getDisplayMetrics().widthPixels;

		View contentView = LayoutInflater.from(context).inflate(
				R.layout.layout_open_red_dialog, null);

		setContentView(contentView, lp);
		hongbao_text= (TextView) contentView.findViewById(R.id.hongbao_text);
		ll_bg = (FrameLayout) contentView.findViewById(R.id.ll_bg);
		tv_other = (TextView) contentView.findViewById(R.id.tv_other);
		ll_open = (FrameLayout) contentView.findViewById(R.id.ll_open);
		close = (ImageView) contentView.findViewById(R.id.close);
		logo = (ImageView) contentView.findViewById(R.id.logo);
		nick = (TextView) contentView.findViewById(R.id.nick);

		close.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dismiss();
			}
		});
	}

    public void setNopakeText(boolean isno){
		if(isno) {
			hongbao_text.setText("手慢了,红包派完了");
			ll_open.setVisibility(View.GONE);
			ll_bg.setBackgroundResource(R.drawable.redpacket3);
		}else{
			hongbao_text.setText("");
			ll_open.setVisibility(View.VISIBLE);
			ll_bg.setBackgroundResource(R.drawable.redpacket2);
		}
	}

	/**
	 * 设置拆红包的监听
	 */
	public void setOpenClickListener(
			final OpenClickListener onOpenClickListener) {
		ll_open.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				if (null != onOpenClickListener) {
					onOpenClickListener.openClick();
				}
			}
		});
		tv_other.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				if (null != onOpenClickListener) {
					onOpenClickListener.otherClick();
				}
			}
		});
	}


	public interface OpenClickListener {
		public void openClick();
		public void otherClick();
	}

	public TextView getNick() {
		return nick;
	}

	public void setNick(TextView nick) {
		this.nick = nick;
	}

	public ImageView getLogo() {
		return logo;
	}

	public void setLogo(ImageView logo) {
		this.logo = logo;
	}
}
